import requests


def get_device_list():
    """
    获取连接设备列表
    :return:
    """
    url = "http://127.0.0.1:5000/api/getDevices"
    response = requests.post(url)
    print(response.json())


def get_device_mm():
    """
    获取设备量程
    :return:
    """
    url = "http://127.0.0.1:5000/api/getDeviceMM"
    payload = dict(sn='M6F-D070-20220523-001')
    response = requests.post(url, json=payload)
    print(response.json())


def get_device_hz():
    """
    获取设备采集频率
    :return:
    """
    url = "http://127.0.0.1:5000/api/getDeviceHZ"
    payload = dict(sn='M6F-D070-20220523-001')
    response = requests.post(url, json=payload)
    print(response.json())


def get_device_de():
    """
    获取设备解耦系数
    :return:
    """
    url = "http://127.0.0.1:5000/api/getDeviceDE"
    payload = dict(sn='M6F-D070-20220523-001')
    response = requests.post(url, json=payload)
    print(response.json())


def set_device_ip():
    """
    设置设备IP
    :return:
    """
    url = "http://127.0.0.1:5000/api/configIP"
    payload = dict(sn='M6F-D070-20220523-001', origin='192.168.0.1', dest='192.1678.0.2')
    response = requests.post(url, json=payload)
    print(response.json())


def set_device_mm():
    """
    设置设备量程
    :return:
    """
    url = "http://127.0.0.1:5000/api/configMM"
    payload = dict(sn='M6F-D070-20220523-001', mm='3')
    response = requests.post(url, json=payload)
    print(response.json())


def set_device_de():
    """
    设置设备解耦系数
    :return:
    """
    url = "http://127.0.0.1:5000/api/configDE"
    payload = dict(sn='M6F-D070-20220523-001', de='1111')
    response = requests.post(url, json=payload)
    print(response.json())


def set_device_hz():
    """
    设置设备采集频率
    :return:
    """
    url = "http://127.0.0.1:5000/api/configHZ"
    payload = dict(sn='M6F-D070-20220523-001', hz='1000')
    response = requests.post(url, json=payload)
    print(response.json())


def set_device_sn():
    """
    设置设备SN
    :return:
    """
    url = "http://127.0.0.1:5000/api/configSN"
    payload = dict(sn='M6F-D070-20220523-001', dest='M6F-D070-20220523-002')
    response = requests.post(url, json=payload)
    print(response.json())


def start_device_collect():
    """
    开始设备采集
    :return:
    """
    url = "http://127.0.0.1:5000/api/startCollect"
    payload = dict(sn='M6F-D070-20220523-001')
    response = requests.post(url, json=payload)
    print(response.json())


def end_device_collect():
    """
    结束设备采集
    :return:
    """
    url = "http://127.0.0.1:5000/api/endCollect"
    payload = dict(sn='M6F-D070-20220523-001')
    response = requests.post(url, json=payload)
    print(response.json())


def take_zero_device_collect():
    """
    设备取零
    :return:
    """
    url = "http://127.0.0.1:5000/api/takeZero"
    payload = dict(sn='M6F-D070-20220523-001')
    response = requests.post(url, json=payload)
    print(response.json())


def get_device_data():
    """
    获取设备上传数据
    :return:
    """
    url = "http://127.0.0.1:5000/api/getDeviceUploadData"
    payload = dict(sn='M6F-D070-20220523-001')
    response = requests.post(url, json=payload)
    print(response.json())


def export_device_data():
    """
    导出设备上传数据
    :return:
    """
    url = 'http://127.0.0.1:5000/api/exportDeviceUploadData'
    payload = dict(sn='M6F-D070-20220523-001')
    response = requests.post(url, json=payload)
    print(response.text)


if __name__ == '__main__':
    get_device_list()
    print('*' * 150)
    get_device_mm()
    print('*' * 150)
    get_device_de()
    print('*' * 150)
    get_device_hz()
    print('*' * 150)
    set_device_ip()
    print('*' * 150)
    set_device_mm()
    print('*' * 150)
    set_device_de()
    print('*' * 150)
    set_device_hz()
    print('*' * 150)
    set_device_sn()
    print('*' * 150)
    start_device_collect()
    print('*' * 150)
    end_device_collect()
    print('*' * 150)
    take_zero_device_collect()
    print('*' * 150)
    get_device_data()
    print('*' * 150)
    export_device_data()


